# coding:utf-8

import time

from lib.base import Base
from page.android import train_12306_order_list_page, train_common_passenger_page, train_accelerate_package_page, \
    train_my_cash_coupon_page, train_mileage_page, train_index_page, train_user_center_page

__author__ = 'weixin.yuan'


class TrainUserCenter(Base):
    """用户中心"""
    def __init__(self, method_name):
        Base.__init__(self, method_name)

        """
        本页元素
        """
        self.cash_coupon_btn = train_user_center_page.elements['代金券按钮']
        self.accelerate_package_btn = train_user_center_page.elements['加速包按钮']
        self.mileage_btn = train_user_center_page.elements['里程按钮']
        self.verification_btn = train_user_center_page.elements['已核验']
        self.login_btn = train_user_center_page.elements['立即登录']
        self.order_12306_btn = train_user_center_page.elements['12306订单']
        self.passenger_btn = train_user_center_page.elements['常用乘客']
        self.login_12306_title = train_user_center_page.elements['登录12306账号title']
        self.login_12306_btn = train_user_center_page.elements['登录12306']

        """
        外部页面元素
        """
        self.user_center_btn = train_index_page.elements['个人中心']
        self.my_cash_coupon_title = train_my_cash_coupon_page.elements['我的代金券title']
        self.accelerate_package_title = train_accelerate_package_page.elements['什么是抢票加速包title']
        self.mileage_title = train_mileage_page.elements['任务中心按钮']
        self.order_12306_title = train_12306_order_list_page.elements['12306订单列表title']
        self.common_passenger_title = train_common_passenger_page.elements['常用乘客title']

    def test_user_center(self):
        """用户中心页面check"""
        self.open_schema_android('6009')

        if self.is_exits(self.cash_coupon_btn):
            time.sleep(5)
            self.click(self.cash_coupon_btn)
        self.check(self.my_cash_coupon_title)
        self.back()

        self.click(self.accelerate_package_btn)
        self.check(self.accelerate_package_title)
        self.back()

        self.click(self.mileage_btn)
        self.check(self.mileage_title)
        self.back()

        if self.is_exits(self.login_btn):
            self.click(self.login_btn)
            self.click(self.login_12306_btn)
        else:
            self.click(self.verification_btn)
            self.check(self.login_12306_title)
            self.back()

        self.click(self.order_12306_btn)
        self.check(self.order_12306_title)
        self.back()

        self.click(self.passenger_btn)
        # self.check(self.common_passenger_title)
